﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using Semantics.Silverlight;
using SilverlightParser.Web.Backend;

namespace SilverlightParser.Web
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ParserService
    {
        [OperationContract]
        public void DoWork()
        {
            // 在此处添加操作实现
            return;
        }

        [OperationContract]
        public List<Semantics.Silverlight.Sentence> GetSentences()
        {
            List<Semantics.Silverlight.Sentence> sentences = Backend.ParseServer.TheServer.GetSentences();
            return sentences;
        }

        [OperationContract]
        public ParseResult Parse(string words)
        {
            ParseResult result = Backend.ParseServer.TheServer.Parse(words);
            return result;
        }

        [OperationContract]
        public ParseResult SelectProcedure(int chilidKey, int selectIndex, string selectValue, string words, ParseResult result)
        {
            return Backend.ParseServer.TheServer.SelectProcedure(chilidKey, selectIndex, selectValue, words, result);

        }
        [OperationContract]
        public LanguageNode TestLangNode()
        {
            LanguageNode langnode = new LanguageNode("中国人民");// LanguageNode.LanguageNodeFromXml(e.Result);
            langnode.Children.Add(new LanguageNode("中国"));
            langnode.Children.Add(new LanguageNode("人民"));
            return langnode;
        }
        // 在此处添加更多操作并使用 [OperationContract] 标记它们
        [OperationContract]
        List<Category> GetSubCategories(int nodeid)
        {
            return SilverlightParser.Web.Backend.Reference.RemotableMentorProxy.GetSubCategories(nodeid);
        }
        [OperationContract]
        int CreateWord(string word, int categorynodeid)
        {
            return SilverlightParser.Web.Backend.Reference.RemotableMentorProxy.CreateWord(word, categorynodeid);
        }
        [OperationContract]
        public List<Semantics.Silverlight.Category> SearchCategories(string word)
        {
           return SilverlightParser.Web.Backend.Reference.RemotableMentorProxy.SearchCategories(word);
        }
        [OperationContract]
        public List<Semantics.Silverlight.Category> GetCategroyHierarchy(int nodeid)
        {
            List<Semantics.Silverlight.Category> results = SilverlightParser.Web.Backend.Reference.RemotableMentorProxy.GetCategroyHierarchy(nodeid);
            return results;
        }
        [OperationContract]
        public DialogueResult Dialogue(DialogueInput input)
        {
            string contact = System.Web.HttpContext.Current.User==null?null:System.Web.HttpContext.Current.User.Identity.Name;
            DialogueResult result = SilverlightParser.Web.Backend.Reference.GetDialogueProxy(contact).Dialogue(input, contact);
            return result;
        }
        [OperationContract]
        public string GetIdentity()
        {
            string contact = System.Web.HttpContext.Current.User == null ? null : System.Web.HttpContext.Current.User.Identity.Name;
            return contact;
        }
    }
}
